﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.crew {
    import Engine.Managers.*;
    import Mechanics.*;
    import Events.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import Classes.*;
    import Classes.util.*;
    import Classes.sim.*;
    import Classes.effects.*;
    import Display.*;
    import Classes.virals.*;
    import Classes.actions.*;
    import Engine.*;
    import Modules.crew.ui.*;
    import Mechanics.GameEventMechanics.*;
    import Modules.stats.types.*;
    import com.zynga.skelly.util.*;

    public class RollCallManager {

        protected var m_activeObjects:Dictionary;

        public function RollCallManager(){
            this.m_activeObjects = new Dictionary();
        }
        public static function debugSample(_arg1:String="", _arg2:String="", _arg3:String="", _arg4:String="", _arg5:int=1):void{
            if (RuntimeVariableManager.getBoolean("ROLL_CALL_DEBUG_ENABLED", false)){
                StatsManager.sample(100, StatsCounterType.DEBUG, "roll_call", _arg1, _arg2, _arg3, _arg4, _arg5);
            };
        }

        public function loadObject(_arg1:Object):void{
            var _local2:String;
            this.m_activeObjects = new Dictionary();
            if (_arg1.active){
                for (_local2 in _arg1.active) {
                    this.m_activeObjects[_local2] = _arg1.active[_local2];
                };
            };
        }
        public function getActiveObject(_arg1:String):MechanicMapResource{
            var _local3:int;
            var _local2:MechanicMapResource;
            if (this.m_activeObjects[_arg1]){
                _local3 = this.m_activeObjects[_arg1];
                _local2 = (Global.world.getObjectById(_local3) as MechanicMapResource);
            };
            return (_local2);
        }
        public function collect(_arg1:String, _arg2:MechanicMapResource):Boolean{
            var _local7:Object;
            var _local8:Boolean;
            var _local3:RollCallDataMechanic = (MechanicManager.getInstance().getMechanicInstance(_arg2, "rollCall", MechanicManager.ALL) as RollCallDataMechanic);
            var _local4:TieredDooberMechanic = (MechanicManager.getInstance().getMechanicInstance(_arg2, "rollCallTieredDooberValue", MechanicManager.ALL) as TieredDooberMechanic);
            var _local5:Array = new Array();
            var _local6:Array = _local3.getCrewState();
            for each (_local7 in _local6) {
                if (((_local7.checkedIn) && ((_local7.purchasedCheckIn == false)))){
                    _local5.push(_local7.zid);
                };
            };
            _local8 = false;
            if (_local3.canCollect(_arg1)){
                _local4.executeOverrideForGameEvent(MechanicManager.ALL).actionSuccess;
                _local8 = _local3.collect(_arg1, false);
                if (!Global.isVisiting()){
                    this.spawnFriendNpcs(_local5, _arg2);
                };
            };
            return (_local8);
        }
        public function canCollect(_arg1:String, _arg2:MechanicMapResource):Boolean{
            var _local3:RollCallDataMechanic = (MechanicManager.getInstance().getMechanicInstance(_arg2, "rollCall", MechanicManager.ALL) as RollCallDataMechanic);
            return (_local3.canCollect(_arg1));
        }
        protected function spawnFriendNpcs(_arg1:Array, _arg2:MapResource):void{
            var _local3:String = Global.gameSettings.getString("npcRollCallTypesFemale", "NPC_Man1");
            var _local4:String = Global.gameSettings.getString("npcRollCallTypesFemale", "NPC_Woman1");
            var _local5:int;
            while (_local5 < _arg1.length) {
                if (((_arg1[_local5]) && (!((_arg1[_local5].charAt(0) == "-"))))){
                    this.createNpc(_arg2, _arg1[_local5], _local3.split(","), _local4.split(","));
                };
                _local5++;
            };
        }
        protected function createNpc(_arg1:MapResource, _arg2:String, _arg3:Array, _arg4:Array):void{
            var _local5:String = ((_arg2.indexOf("-") >= 0)) ? "-1" : _arg2;
            var _local6:Item = _arg1.getItem();
            if (_local6){
                StatsManager.sample(100, StatsCounterType.GAME_ACTIONS, _local6.type, "friend_npc_spawn", _local6.name);
            };
            var _local7:String;
            var _local8:Player = Global.player.findFriendById(_local5);
            if (_local8){
                _local7 = _local8.snUser.picture;
            };
            var _local9:Array = (((!(_local8)) || ((_local8.snUser.gender == "male")))) ? _arg3 : _arg4;
            var _local10:Road = Global.world.citySim.roadManager.findClosestRoad(_arg1.getPosition());
            var _local11:NPC = Global.world.citySim.npcManager.createWalkerByNameAtPosition(MathUtil.randomElement(_local9), _local10.getHotspot(), true);
            _local11.actionSelection = new AmbientNPCActionSelection(_local11);
            _local11.actionQueue.addActions(new ActionAnimationEffect(_local11, EffectType.POOF));
            _local11.slidePick = new NPCSlidePick(_local11, _local7, Curry.curry(this.onNpcClick, _local11, _local5, _arg1));
            _local11.showSlidePick();
            _local11.playActionCallback = Curry.curry(this.onNpcClick, _local11, _local5, _arg1);
        }
        protected function onNpcClick(_arg1:NPC, _arg2:String, _arg3:MapResource):void{
            var npc:* = _arg1;
            var friendId:* = _arg2;
            var building:* = _arg3;
            if (((!(friendId)) || ((friendId.charAt(0) == "-")))){
                return;
            };
            var item:* = building.getItem();
            if (item){
                StatsManager.sample(100, StatsCounterType.GAME_ACTIONS, item.type, "friend_npc_click", item.name);
            };
            var iconUrl:* = null;
            var friendLocName:* = Global.player.getFriendFirstName(Player.FAKE_USER_ID_STRING);
            var friend:* = Global.player.findFriendById(friendId);
            if (friend){
                iconUrl = friend.snUser.picture;
                friendLocName = Global.player.getFriendFirstName(friendId);
            };
            var customOk:* = ZLoc.t("Dialogs", "RollCallCollectionReminder_button", {friendName:friendLocName}).toUpperCase();
            var message:* = ZLoc.t("Dialogs", "RollCallCollectionReminder_message", {friendName:friendLocName});
            UI.displayViralShareMessage(ViralType.ROLL_CALL_COLLECTION_REMINDER, message, GenericDialogView.TYPE_CUSTOM_OK, Curry.curry(this.onCollectionReminderClose, friendId, building), "RollCallCollectionReminder", false, iconUrl, "RollCallCollectionReminder", GenericDialogView.ICON_POS_LEFT, customOk, false);
            if (npc){
                npc.hideSlidePick(0.5);
                npc.getStateMachine().removeAllStates();
                npc.getStateMachine().addActions(new ActionTween(npc, ActionTween.TO, 0.5, {alpha:0}), new ActionFn(npc, Curry.curry(function (_arg1:NPC):void{
                    Global.world.citySim.npcManager.removeWalker(_arg1);
                }, npc)));
            };
        }
        protected function onCollectionReminderClose(_arg1:String, _arg2:MapResource, _arg3:GenericPopupEvent):void{
            if (_arg3.button == GenericDialogView.YES){
                Global.world.viralMgr.sendRollCallCollectReminder(_arg1, _arg2);
            };
        }

    }
}//package Modules.crew 
